﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tong;
using Tong.Fy;
using JModel;
using System.Linq;
public partial class aspnet_testPargrameDir_bock_Column_CX_Column_Temp_Show : System.Web.UI.Page
{
    /// <summary>
    /// 表名
    /// </summary>
    public string Tab = "RegUser";

    /// <summary>
    /// 栏目名
    /// </summary>
    public string Column_Name = "";

    /// <summary>
    /// 显示所有数据
    /// </summary>
    public string TextHTMLout = "";

    public TongUse TextData = new TongUse();
    /// <summary>
    /// 分页类
    /// </summary>
    FenYe FY = new FenYe();

    /// <summary>
    /// 数据操作
    /// </summary>
    DBEntities db = new DBEntities();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    //看看是不是要删除数据
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");

            l.Attributes.Add("onclick", "javascript:return " +

            "confirm('您确定要删除 " +

            DataBinder.Eval(e.Row.DataItem, "Cx_keyWord_Name") + "吗?')");

        }

    }

    /// <summary>
    /// 初始化变量
    /// </summary>
    protected void PageLand()
    {
        try
        {
            Tab = "RegUser";
            Column_Name = "会员管理";
            this.Title = "显示" + Column_Name + "的内容";


        }
        catch
        {
            //TextData.Err("些页面不能直接访问");
            Response.End();
        }

    }

    protected void BindData()
    {
        PageLand();
        DataTable TempTab = new DataTable();
        DataGrid GG1 = new DataGrid();

        GG1.DataSource = FY.Fy("SELECT * FROM [" + Tab + "] order by [" + Tab + "_id] desc", 50);
        GG1.DataBind();
        Div.InnerHtml = FY.GetHTML;
        TextHTMLout = "";
        for (int i = 0; i < GG1.Items.Count; i++) //GG1.Items.Count 得 到 行
        {
            //for (int j = 0; j < GG1.Items[i].Cells.Count; j++) //得到列
            //{
               // Response.Write("<br/>"+GG1.Items[i].Cells[j].Text +"行<br>//////////////////////////////// "+j+" <br>");//输出数据
                
                // 0 id ; 1 标题 ; 2 内容 ; 3 时间 ; 4图片 ; 5 说明 ; 
            //}

            TextHTMLout += "  <tr>\r\n" +
"<td align=\"center\" class='tdbg' style='height: 27px'>" + GG1.Items[i].Cells[0].Text.ToString() + "</strong></td>\r\n" +
"<td align=\"left\" class='tdbg' style='height: 27px'> <a href='CX_Column_Temp_Edit.aspx?id=" + GG1.Items[i].Cells[0].Text.ToString() + "&Tab=" + Tab + IsShowElement() + "' class='link1' >" + GG1.Items[i].Cells[1].Text.ToString() + " </a></td>\r\n" +
"<td align=\"left\" class='tdbg' style='height: 27px'>" + GG1.Items[i].Cells[5].Text.ToString() + "</td>\r\n" +
"<td align=\"center\" class='tdbg' style='height: 27px'>" + GG1.Items[i].Cells[3].Text.ToString() + "</td>\r\n" +
"<td align=\"left\" class='tdbg' style='height: 27px'><a href='CX_Column_Temp_Edit.aspx?id=" + GG1.Items[i].Cells[0].Text.ToString() + "&Tab=" + Tab + IsShowElement() + "' class='link1' >编辑 " + GG1.Items[i].Cells[1].Text.ToString() + " </a>   &nbsp;  &nbsp;   &nbsp;  &nbsp; <a href=\"javascript:Del('CX_Column_Temp_Del.aspx?id=" + GG1.Items[i].Cells[0].Text.ToString() + "&Tab=" + Tab + IsShowElement() + "','" + GG1.Items[i].Cells[1].Text.ToString() + "');\" class='link'>  删除   </a></td>\r\n" +
"</tr>\r\n";

          
        }

        Records.DataSource = GG1.DataSource;
        Records.DataBind();

        GG1 = null;


           
        ////开始遁环显示数据
        //for (int i = 0; i < TempTab.Rows.Count; i++)
        //{
        //    TextHTMLout += "  <tr>\r\n" +
        //    "<td align=\"center\" class='tdbg' style='height: 27px'>"+TempTab.Rows[i][Tab+"_id"].ToString()+"</strong></td>\r\n"+
        //    "<td align=\"left\" class='tdbg' style='height: 27px'> <a href='CX_Column_Temp_Edit.aspx?id=" + GG1.Items[i].Cells[0].ToString() + "&Tab="+Tab+"' class='link1' >" + GG1.Items[i].Cells[1].ToString() + " </a></td>\r\n" +
        //    "<td align=\"left\" class='tdbg' style='height: 27px'>" + GG1.Items[i].Cells[5].ToString() + "</td>\r\n" +
        //    "<td align=\"center\" class='tdbg' style='height: 27px'>" + GG1.Items[i].Cells[3].ToString() + "</td>\r\n" +
        //    "<td align=\"left\" class='tdbg' style='height: 27px'><a href='CX_Column_Temp_Edit.aspx?id=" + GG1.Items[i].Cells[0].ToString() + "&Tab=" + Tab + "' class='link1' >编辑 " + GG1.Items[i].Cells[1].ToString() + " </a>   &nbsp;  &nbsp;   &nbsp;  &nbsp; <a href='CX_Column_Temp_Del.aspx?id=" + GG1.Items[i].Cells[0].ToString() + "&Tab=" + Tab + "'class='link'>  删除   </a></td>\r\n" +
        //    "</tr>\r\n";

            
        //}


       

    }

    /// <summary>
    /// 删除数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void LinkButton1_Click(object sender, EventArgs e)
    { 
    
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        PageLand();
        DataGrid GG1 = new DataGrid();

        GG1.DataSource = FY.Fy("select * from [" + Tab + "]  where [" + Tab + "_LX] like '%" + Cx_keyWord_Name.Text.Trim() + "%' order by [" + Tab + "_id] desc", 5000);
        GG1.DataBind();

        Div.InnerHtml = FY.GetHTML;
        TextHTMLout = "";
        for (int i = 0; i < GG1.Items.Count; i++) //GG1.Items.Count 得 到 行
        {
            //for (int j = 0; j < GG1.Items[i].Cells.Count; j++) //得到列
            //{
            // Response.Write("<br/>"+GG1.Items[i].Cells[j].Text +"行<br>//////////////////////////////// "+j+" <br>");//输出数据

            // 0 id ; 1 标题 ; 2 内容 ; 3 时间 ; 4图片 ; 5 说明 ; 
            //}

            TextHTMLout += "  <tr>\r\n" +
"<td align=\"center\" class='tdbg' style='height: 27px'>" + GG1.Items[i].Cells[0].Text.ToString() + "</strong></td>\r\n" +
"<td align=\"left\" class='tdbg' style='height: 27px'> <a href='CX_Column_Temp_Edit.aspx?id=" + GG1.Items[i].Cells[0].Text.ToString() + "&Tab=" + Tab + IsShowElement() + "' class='link1' >" + GG1.Items[i].Cells[1].Text.ToString() + " </a></td>\r\n" +
"<td align=\"left\" class='tdbg' style='height: 27px'>" + GG1.Items[i].Cells[5].Text.ToString() + "</td>\r\n" +
"<td align=\"center\" class='tdbg' style='height: 27px'>" + GG1.Items[i].Cells[3].Text.ToString() + "</td>\r\n" +
"<td align=\"left\" class='tdbg' style='height: 27px'><a href='CX_Column_Temp_Edit.aspx?id=" + GG1.Items[i].Cells[0].Text.ToString() + "&Tab=" + Tab + IsShowElement() + "' class='link1' >编辑 " + GG1.Items[i].Cells[1].Text.ToString() + " </a>   &nbsp;  &nbsp;   &nbsp;  &nbsp; <a href=\"javascript:Del('CX_Column_Temp_Del.aspx?id=" + GG1.Items[i].Cells[0].Text.ToString() + "&Tab=" + Tab + IsShowElement() + "','" + GG1.Items[i].Cells[1].Text.ToString() + "');\" class='link'>  删除   </a></td>\r\n" +
"</tr>\r\n";


        }
        Records.DataSource = GG1.DataSource;
        Records.DataBind();


        GG1 = null;


        //GridView1.DataSource = TextData.SqlataSet("select * from [" + Tab + "]  where " + Tab + "_Name like '%" + Cx_keyWord_Name.Text.Trim() + "%' order by " + Tab + "_id desc").Tables[0].DefaultView;
       // GridView1.DataBind();
    }
    /// <summary>
    /// 编辑事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void KeyWord_edit_Click(object sender, EventArgs e)
    {
        string RedirID = ((LinkButton)sender).CommandArgument.ToString();
        if (RedirID != "")
        {
            Response.Redirect("CX_Column_Temp_Edit.aspx?id=" + RedirID + "&Tab=" + Tab+IsShowElement());
        }
    }




    /// <summary>
    /// 删除事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void delcc(object sender, EventArgs e)
    {

        string RedirID = ((LinkButton)sender).CommandArgument.ToString();
        if (RedirID != "")
        {
            try
            {
                TextData.SqlDataSave("delete [" + Tab + "] where " + Tab + "_id = " + RedirID);
                tt.Text = "";
                tt.Text = "删除 信息成功";
                BindData();
            }
            catch
            {
                tt.Text = "";
                tt.Text = "删除  时出现错误　操作没有完成 ";
            }
        }

    }

    public String IsShowElement()
    {
        string scripttext = "";
        // Pic 显示小图片
        try
        {
            
            if (Convert.ToBoolean(Request.QueryString["Pic"].ToString()))
            {
                scripttext += "&Pic=true";
            }
            else
            {
                scripttext += "";
            }
        }
        catch
        {
            
        }

        // Cont 显示内容
        try
        {
            if (Convert.ToBoolean(Request.QueryString["Cont"].ToString()))
            {
                scripttext += "&Cont=true";
            }
            else
            {
                scripttext += "";
            }
        }
        catch
        {
            scripttext += "";
        }

        // Expiler 说明
        try
        {
            if (Convert.ToBoolean(Request.QueryString["Expiler"].ToString()))
            {
                scripttext += "&Expiler=true";
            }
            else
            {
                scripttext += "";
            }
        }
        catch
        {
            scripttext += "";
        }


        // Crtfile 生成文件名 
        try
        {
            if (Convert.ToBoolean(Request.QueryString["Crtfile"].ToString()))
            {
                scripttext += "&Crtfile=true";
            }
            else
            {
                scripttext += "";
            }
        }
        catch
        {
            scripttext += "";
        }

        // Sort 排序
        try
        {
            if (Convert.ToBoolean(Request.QueryString["Sort"].ToString()))
            {
                scripttext += "&Sort=true";
            }
            else
            {
                scripttext += "";
            }
        }
        catch
        {
            scripttext += "";
        }

        // ShowLx 显示类型 
        try
        {
            if (Convert.ToBoolean(Request.QueryString["ShowLx"].ToString()))
            {
                scripttext += "&ShowLx=true";
            }
            else
            {
                scripttext += "";
            }
        }
        catch
        {
            scripttext += "";
        }

        // linkxx 链接地址
        try
        {
            if (Convert.ToBoolean(Request.QueryString["linkxx"].ToString()))
            {
                scripttext += "&linkxx=true";
            }
            else
            {
                scripttext += "";
            }
        }
        catch
        {
            scripttext += "";
        }


        return scripttext;
    }
    /// <summary>
    /// 还原初始密码
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void DefalutPwd_Click(object sender, EventArgs e)
    {
        string RedirID = ((LinkButton)sender).CommandArgument.ToString();
        decimal id = 0;
        decimal.TryParse(RedirID, out id);
        var result=  db.RegUser.FirstOrDefault(p => p.RegUser_id ==id);
        if (result != null)
        {
            //默认密码已经修改为123456
            result.RegUser_CreatefileName = "123456";
        }
        db.SaveChanges();
        RegisterClientScriptBlock("alt", "<script>alert('已经设置初始密码为:" + result.RegUser_CreatefileName + "');</script>");
    }

    /// <summary>
    /// 内容状态保存时发生
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public void Page_SaveStateComplete(object sender, EventArgs e)
    {

        db.Connection.Close();
        db.Dispose();
    }
}
